package com.example.cinema.bindingdata;

import android.view.View;
import android.widget.ImageView;

import androidx.databinding.BindingAdapter;
import androidx.databinding.ObservableField;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.example.cinema.R;
import com.example.cinema.drawview.ShortPlayerVideo;

public class ShortBindingData {
    @BindingAdapter("imgurl")
    public static void seturl(View view,String url)
    {
        if(url==null)
        {
            return;
        }
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.head_img)
                .error(R.mipmap.head_img)
                .fallback(R.mipmap.head_img);
        Glide.with(view).load(url)
                .apply(options)
                .into((ImageView) view);
    }
    @BindingAdapter("url")
    public static void setPlayurl(View view,String url){ //自定义View属性映射
        if(view != null)
        {
            ShortPlayerVideo video = (ShortPlayerVideo) view;//转为自定义View
            video.setPlayurl(url);//向自定义View设置的传值方法传值
        }
    }
    @BindingAdapter("coverurl")
    public static void setCoverImg(View view,String url)
    {
        if(url!=null)
        {
            ShortPlayerVideo playerVideo = (ShortPlayerVideo) view;
            playerVideo.setImgUrl(url);
        }
    }


    public ObservableField<String> title = new ObservableField<>();//标题
    public ObservableField<String> texts = new ObservableField<>();//内容
    public ObservableField<String> image = new ObservableField<>();//视频封面
    public ObservableField<String> playurl = new ObservableField<>();//视频url
    public ObservableField<String> videoid = new ObservableField<>();//视频ID
    public ObservableField<String> imgurl = new ObservableField<>();//用户头像
    public ObservableField<String> videourl = new ObservableField<>();//完整版播放地址
    public ObservableField<String> useruid = new ObservableField<>();//用户ID

    public ObservableField<String> lovenum = new ObservableField<>();//用户点赞
    public ObservableField<String> centimg = new ObservableField<>();//内容图片


}
